@echo off
CHCP 65001 > nul

REM === 检查Python环境 ===
where python >nul 2>&1
if %errorlevel% neq 0 (
    echo Python未安装，请先安装Python
    pause
    exit /b 1
)

REM === 检查依赖 ===
set "dependencies=PyQt5 pywin32 pyyaml pymssql"
set "missing_dependencies="
for %%i in (%dependencies%) do (
    python -c "import %%i" >nul 2>&1
    if %errorlevel% neq 0 (
        set "missing_dependencies=!missing_dependencies! %%i"
    )
)

REM === 依赖管理流程 ===
if defined missing_dependencies (
    echo 以下依赖未安装:!missing_dependencies!
    echo 正在安装依赖...
    pip install -r requirements.txt
    if %errorlevel% neq 0 (
        echo 依赖安装失败
        pause
        exit /b 1
    )
    echo 依赖安装成功
) else (
    echo 所有依赖已安装
)

REM === 启动程序 ===
echo 启动程序...
python main.py
if %errorlevel% equ 0 (
    @REM pause
) else (
    @REM pause
    exit /b 1
)